package com.promise.jokerdream.database.entity

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey
import com.promise.jokerdream.config.game.BaseGameConfig
import kotlinx.serialization.Serializable

/**
 * 星座配置实体 - 独立的完整表，直接作为业务对象使用
 */
@Serializable
@Entity(
    tableName = "constellation_game_config",
    foreignKeys = [
        ForeignKey(
            entity = UserConfigEntity::class,
            parentColumns = ["userId"],
            childColumns = ["userId"],
            onDelete = ForeignKey.CASCADE
        )
    ],
    indices = [Index(value = ["userId"], unique = true)]
)
data class ConstellationGameConfigEntity(
    @PrimaryKey
    val userId: String,
    override val enabledSetting: Boolean = true,
    override val scheduledChallengeEnabled: Boolean = false,
    override val registrationTime: String = "",
    val levelName: String = ""
) : BaseGameConfig {
    /**
     * 获取关卡ID
     * 支持格式：1-白羊宫 或 纯数字
     * @return 关卡ID，如果解析失败返回null
     */
    fun getSceneId(): Int? {
        return if (levelName.contains("-")) {
            levelName.split("-").firstOrNull()?.toIntOrNull()
        } else {
            levelName.toIntOrNull()
        }
    }
}

